package com.wht.service.music.impl;

import com.wht.mapper.music.FindMusicDao;
import com.wht.mapper.music.impl.FindMusicDaoImpl;
import com.wht.domain.Music;
import com.wht.domain.PageBean;
import com.wht.domain.Singer;
import com.wht.service.music.FindMusicService;

import java.util.List;

/**
 * @author wanghaotian
 * time:2022/11/21,0021 21:34
 * description:
 */

public class FindMusicServiceImpl implements FindMusicService {
    private FindMusicDao findMusicDao = new FindMusicDaoImpl();
    @Override
    public List<Music> findAllMusic() {
        return findMusicDao.selectAllMusic();
    }

    @Override
    public Music findMusicById(String id) {
        return findMusicDao.selectMusicById(id);
    }

    @Override
    public PageBean<Music> findPageByCurrentPage(Integer currentPage,Integer pageSize) {
        //1.创建PageBean对象,封装分页数据
        PageBean<Music> pageBean = new PageBean<Music>();
        //2.封装当前页码数字
        pageBean.setCurrentPage(currentPage);
        //3.封装每页显示的具体条数
        pageBean.setPageSize(pageSize);
        //4.封装每页显示的具体数据
        List<Music> list = findMusicDao.findByPage(currentPage, pageSize);
        pageBean.setList(list);
        //5.封装总的条数
        Number number= findMusicDao.findTotalCount();
        int totalCount =number.intValue();
        pageBean.setTotalCount(totalCount);
        //6.封装总的页码数: 总的条数101  每页显示10条
        Integer totalPage  = (totalCount%pageSize==0)?
                totalCount/pageSize : ((totalCount/pageSize)+1);
        pageBean.setTotalPage(totalPage);
        return pageBean;
    }

    @Override
    public List<Singer> findSinger() {
        return findMusicDao.selectSinger();
    }
}
